$(function() {

	$.ajax({
		url: "http://localhost:8080/mall/findAllOrderDetails",
		dataType: "json",
		success: function(result) {
			var data = result.message;
			var code=data[1].orderDetails[0].orderCode;
			console.log(data);
			// console.log(code);
			var str = `<div class="wo"><span class="title">我的订单</span></div>`;
			for (var i = 0; i < data.length; i++) {
				
				str +=
					`
						<div class="text">
							<div class="t-time">${data[i].created}</div>
							<div class="t-identifier">${data[i].orderCode}</div>
							<div class="t-num">单价</div>
							<div class="t-sum">数量</div>
							<div class="t-action">商品操作</div>
							<div class="t-pay">实付金额</div>
							<div class="t-detail" onclick="search(${data[i].orderCode},${data[i].status},${data[i].closeTime},${data[i].address_id})">查看详情></div>
						</div>
						
						<div class="cart-item-list">
							<div class="cart-item check-cart-item">
								<div class="p-goods">
									<div class="p-img">
										<img src="${data[i].orderDetails[0].itemImage}" alt="">
									</div>
									<div class="p-msg">${data[i].orderDetails[0].itemTitle}</div>
								</div>
								<div class="p-price">${data[i].orderDetails[0].itemPrice}</div>
								<div class="p-num">
									<div class="quantity-form">
										${data[i].orderDetails[0].itemNum}
									</div>
								</div>
								<div class="p-action"><button type="button" onclick="del(${data[i].orderDetails[0].orderCode})" class="del" >删除此订单</button></div>
								<div class="p-sum">${data[i].orderDetails[0].total}</div>
								<div class="p-detail"></div>
							</div>
						</div>
					`
			}

			$("#my").html(str)

		}
	})

})


function search(code,id,date,addressId) {
	
	var unixTimestamp = new Date(date) ;
	commonTime = unixTimestamp.toLocaleString();
	 // console.log(commonTime);
	// console.log(code)
	window.location.href = "details.html?value="+code+"&value2="+id+"&value3="+commonTime+"&value4="+addressId;
}

Date.prototype.toLocaleString = function() {
          return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 " + this.getHours() + "点" + this.getMinutes() + "分" + this.getSeconds() + "秒";
    };




function del(id){
	// console.log(id)
	$.ajax({
		url: "http://localhost:8080/mall/deleteOrder?order_code="+id,
		dataType: "json",
		success: function(result) {
			location.reload();
		}
	})
}





